/*
 ============================================================================
 Name		: RtSingleTimer.cpp
 Author	  : hou maoqing
 Version	 : 1.0
 Copyright   : Copyright (c) Hou maoqing 2008
 houmqing@sohu.com
 Description : CRtSingleTimer implementation
 ============================================================================
 */

#include "RtSingleTimer.h"

CRtSingleTimer::CRtSingleTimer(MRtSingleTimerObserver& rObserver,int nID) :
	CActive(EPriorityStandard), // Standard priority
	m_rObserver(rObserver),
	m_nID(nID)
	{
	ConstructL();
	}

void CRtSingleTimer::ConstructL()
	{
	User::LeaveIfError(iTimer.CreateLocal() ); // Initialize timer
	CActiveScheduler::Add( this); // Add to scheduler
	}

CRtSingleTimer::~CRtSingleTimer()
	{
	Cancel(); // Cancel any request, if outstanding
	iTimer.Close(); // Destroy the RTimer object
	}

int CRtSingleTimer::GetID()
	{
	return m_nID;
	}

void CRtSingleTimer::DoCancel()
	{
	iTimer.Cancel();
	}

void CRtSingleTimer::After(TTimeIntervalMicroSeconds32 aDelay)
	{
	Cancel(); // Cancel any request, just to be sure
	iTimer.After(iStatus, aDelay); // Set for later
	SetActive(); // Tell scheduler a request is active
	}

void CRtSingleTimer::RunL()
	{
	m_rObserver.TimerFinished(m_nID);
	}

TInt CRtSingleTimer::RunError(TInt aError)
	{
	return aError;
	}
